package IOperation;

import Book.BookList;
import Book.book;

import java.util.Scanner;

public class addOperation implements  IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加书");
    // 1.判断书架是不是还有位置
        int currentBookSize = bookList.getBookSize();
        if(currentBookSize == bookList.getBook().length)
            System.out.println("存放失败 ，书架位置不够");
        //2. 创建一个新的书类
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = scanner.nextLine();
        System.out.println("请输入作者名：");
        String author = scanner.nextLine();
        System.out.println("请输入书的类型");
        String type = scanner.nextLine();
        book b = new book(name,author,type);
        //3.判断是否已经添加过
        for (int i = 0; i < bookList.getBookSize(); i++) {
           if(bookList.getBook(i).getName().equals(name)){
               System.out.println("已经添加过");
           }
        } // 4.  添加新的书
        bookList.setBook( bookList.getBookSize(),b);
        bookList.setBookSize( bookList.getBookSize()+1);
//        System.out.println(bookList.getBookSize());
        System.out.println("添加成功！");
    }
}
